from examination.scoring.interface.scoring_utils import ScoringUtils
from examination.scoring.iml.code_scoring import CodeScoring

class ScoringFactory:

    _instance = None
    __contextDict = {}

    def __new__(cls):
        if not cls._instance:
            cls._instance = super(ScoringFactory, cls).__new__(cls)
        return cls._instance
    def __init__(self):
        if not ScoringFactory.__contextDict:  # 只在首次初始化时创建
            app = self.__initFlaskApp()
            ScoringFactory.__contextDict["app"] = app
            cache = self.__initCache(app=app)
            ScoringFactory.__contextDict["cache"] = cache
    @classmethod
    def getScoringUtils(topic_type)->ScoringUtils:
        if topic_type == "code":
            return CodeScoring()
        else:
            raise ValueError("Invalid topic type")
            return None

if __name__ == "__main__":
    scoring_utils = ScoringFactory.getScoringUtils("code")
    print(scoring_utils)